package com.ssy.lingxi.order.entity;

import com.fasterxml.jackson.annotation.JsonBackReference;
import com.ssy.lingxi.order.handler.converter.JpaJsonToRequirementConverter;
import com.ssy.lingxi.order.model.bo.OrderRequirementDetailBO;

import javax.persistence.*;
import java.io.Serializable;

/**
 * 订单其他要求
 * @author 万宁
 * @version 2.0.0
 * @date 2021-07-17
 */
@Entity
@Table(schema = "public", name = "ord_requirement", indexes = {@Index(name = "ord_requirement_order_id_idx", columnList = "order_id")})
public class OrderRequirementDO implements Serializable {
    private static final long serialVersionUID = 2888189706636526866L;

    /**
     * 主键Id
     */
    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "ord_requirement_seq")
    @SequenceGenerator(sequenceName = "ord_requirement_seq", name = "ord_requirement_seq", allocationSize = 1)
    private Long id;

    /**
     * 一对一双向关联订单
     */
    @JsonBackReference
    @OneToOne(cascade = CascadeType.DETACH, fetch = FetchType.LAZY)
    @JoinColumn(name="order_id", referencedColumnName="id")
    private OrderDO order;

    /**
     * 其他要求详情
     */
    @Convert(converter = JpaJsonToRequirementConverter.class)
    @Column(columnDefinition = "jsonb")
    public OrderRequirementDetailBO detail;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public OrderDO getOrder() {
        return order;
    }

    public void setOrder(OrderDO order) {
        this.order = order;
    }

    public OrderRequirementDetailBO getDetail() {
        return detail;
    }

    public void setDetail(OrderRequirementDetailBO detail) {
        this.detail = detail;
    }
}
